#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Last Update:

import sys
sys.path.append('.')
sys.path.append('..')
import wx

class MainPanel(wx.Panel):
    def __init__(self, parent, log, **kargs):
        wx.Panel.__init__(self, parent)
        self.log = log
        self.canCapture = wx.CheckBox(self, -1, u'开启高级功能')
        self.canAnswer = wx.CheckBox(self, -1, u'自动答题')
        self.canFarm = wx.CheckBox(self, -1, u'自动农场')
        self.canBuild = wx.CheckBox(self, -1, u'自动建筑')
        self.checkBoxes= ('canCapture', 'canAnswer', 'canFarm', 'canBuild')
        
        self.layout()
        
    def layout(self):
        self.Center()
        setupBox = wx.StaticBox(self, -1, u'基本设置')
        setupSizer = wx.StaticBoxSizer(setupBox, wx.VERTICAL)
        for name in self.checkBoxes:
            setupSizer.Add(getattr(self, name), 0, wx.EXPAND|wx.ALL, 5)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(setupSizer, 0, wx.EXPAND|wx.ALL, 5)

        self.SetSizer(mainSizer)

    def getData(self, data = {}):
        for name in self.checkBoxes:
            data.update({name:getattr(self, name).GetValue()})
        return data

    def setData(self, data):
        for name in self.checkBoxes:
            getattr(self, name).SetValue(data[name])

if __name__ == '__main__':
    import config
    app = wx.PySimpleApp()
    mainFrame = wx.Frame(None, -1, 'main', size=(800, 600))
    panel = MainPanel(mainFrame, config.log)
    data = {'farmCount': {'kind': 'lv', 'value': 4}, 'canAnswer': True, 'farmAction': 2, 'farmKind': {'food': True, 'stone': True, 'wood': True, 'bronze': True}, 'canFarm': True, 'canCapture': True, 'canBuild': True}
    panel.setData(data)
    mainFrame.Show()
    app.MainLoop()    

